package binarysearch.寻找旋转排序数组中的最小值;

public class Solution {
    public int findMin(int[] nums) {
        int[] ans = new int[]{nums[0]};
        findMin(nums, 0, nums.length - 1, ans);
        return ans[0];
    }

    /**
     * 求旋转后最小的值
     */
    void findMin(int[] nums, int start, int end, int[] ans) {
        if (start > end) {
            return;
        }
        int mid = (start + end) / 2;
        ans[0] = Math.min(ans[0], nums[start]);
        if (nums[start] > nums[mid]) {
            findMin(nums, start, mid , ans);
        }
        if (nums[mid] > nums[end]) {
            findMin(nums, mid + 1, end, ans);
        }
    }
    /**
     * 7,8,9,0,1,2
     */
    public static void main(String[] args) {
        System.out.println(new Solution().findMin(new int[]{3,1,2}));
    }
}

